-- @owner: @zhanghuan96
-- @date: 2024/12/12
-- @testpoint: 存储过程/自定义函数没有嵌套，调用gms_UTILITY.FORMAT_CALL_STACK函数
@conn PrimaryDbAmode;
--前置条件
drop extension if exists gms_utility;
create extension gms_utility;
--step1:创建存储过程;expect:成功
drop PROCEDURE if exists proc_format0004_01;
CREATE OR REPLACE PROCEDURE proc_format0004_01 AS
  v_call_stack VARCHAR2(32767);
BEGIN
  v_call_stack := gms_UTILITY.FORMAT_CALL_STACK;
  RAISE INFO 'INFO:Current Call Stack:';
  RAISE INFO 'INFO:%', v_call_stack;  
  NULL;
END proc_format0004_01;
/

--step2:调用存储过程;expect:输出堆栈信息
call proc_format0004_01();
--step3:创建自定义函数，使用gms_utility.format_call_stack函数;expect:成功
drop function if exists func_format0004_01;
create or replace function func_format0004_01
returns void as $$
begin
    RAISE INFO 'INFO:func_format0004_01 call stack: ';
    RAISE INFO 'INFO:%', gms_utility.format_call_stack();
end;
$$ language plpgsql;
/
drop function if exists func_format0004_02;
create or replace function func_format0004_02
returns void as $$
begin
    func_format0004_01();
end;
$$ language plpgsql;
/
--step4:调用函数;expect:成功，打印堆栈信息
select func_format0004_01();
--step5:调用嵌套函数;expect:成功，打印函数1和函数2的堆栈信息
select func_format0004_02();
--step6:清理环境;expect:成功
drop PROCEDURE if exists proc_format0004_01;
drop function if exists func_format0004_01;
drop function if exists func_format0004_02;
drop extension if exists gms_utility;